<?php

/**
 * 用户模型
 * @author harvey
 */

namespace Admin\Model;

use Think\Model;

class MemberInfoModel extends Model {
	protected $tableName = 'weixin_user'; 

	function _initialize()
	{
		// $this->option = M('fotile520_option');
	}
	/**
	*信息
	*/
	public function getWinUser($condition = [],$pagesize=5){
		$map=[];
		if (array_key_exists('realname', $condition) && !empty($condition['realname'])) {
			$realname=$condition['realname'];
            $map['realname'] = array("like", "%" . $realname . "%");
        }
        if (array_key_exists('phone', $condition) && !empty($condition['phone'])) {
        	 $phone = $condition['phone'];
             $map['phone'] = array("like", "%" . $phone . "%");
        }
        if (array_key_exists('nickname', $condition) && ($condition['nickname'])) {
        	 $nickname = $condition['nickname'];
             $map['nickname'] = array("like", "%" . $nickname . "%");
        }
        if (array_key_exists('firtime', $condition) && ($condition['firtime']) && array_key_exists('sectime', $condition) && ($condition['sectime'])) {
            $fir1 =explode('-',$condition['firtime'])[0];
            $fir2 =explode('-',$condition['firtime'])[1];
            $fir3 =explode('-',$condition['firtime'])[2];

            $sec1 =explode('-',$condition['sectime'])[0];
            $sec2 =explode('-',$condition['sectime'])[1];
            $sec3 =explode('-',$condition['sectime'])[2];


            $firtime = mktime(0,0,0,$fir2,$fir3,$fir1);
            $sectime = mktime(23,59,59,$sec2,$sec3,$sec1); 
            // echo $firtime;die;
            $map['update_time'] =array('between',"$firtime,$sectime");        
        }
        if (array_key_exists('newstart', $condition) && ($condition['newstart']) && array_key_exists('newend', $condition) && ($condition['newend'])) {
            $fir1 =explode('-',$condition['newstart'])[0];
            $fir2 =explode('-',$condition['newstart'])[1];
            $fir3 =explode('-',$condition['newstart'])[2];

            $sec1 =explode('-',$condition['newend'])[0];
            $sec2 =explode('-',$condition['newend'])[1];
            $sec3 =explode('-',$condition['newend'])[2];


            $newstart = mktime(0,0,0,$fir2,$fir3,$fir1);
            $newend = mktime(23,59,59,$sec2,$sec3,$sec1); 
            // echo $firtime;die;
            $map['create_time'] =array('between',"$newstart,$newend");        
        }

		// $res = $this->option->alias('us')->join('RIGHT JOIN eosi_weixin_user as wx ON us.user_id = wx.id')->where($map)->select();
		// $count = count($res);
		$count = $this->where($map)->count();
		$Page = new \Admin\ORG\PageNew($count, $pagesize);;
		// $list = $this->option->alias('us')->join('RIGHT JOIN eosi_weixin_user as wx ON us.user_id = wx.id')->where($map)->order('wx.id desc')->field('wx.id,openid,nickname,sex,province,country,city,headimgurl,realname,phone,address,score,options,created_at,wx.update_time,wx.create_time')->limit($Page->firstRow.','.$Page->listRows)->select();
		$list = $this->where($map)->order('update_time desc')->limit($Page->firstRow.','.$Page->listRows)->select();
		// echo $this->getLastSQL();
		$show = $Page->show();// 分页显示输出
		$ListArray = [];
		$ListArray['list']  = $list;
		$ListArray['show']  = $show;
		return $ListArray;
	} 
	
}    